package com.spring.aop;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

public class TestCglibProxy {

	public static void main(String[] args) {
		IHelloService helloService = new HelloService();

		Enhancer enhancer = new Enhancer();
		enhancer.setClassLoader(TestCglibProxy.class.getClassLoader());
		enhancer.setSuperclass(HelloService.class);
		enhancer.setCallback(new InvocationHandler() {
			@Override
			public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
				System.out.println("------cglib before");
				Object invoke = method.invoke(helloService, objects);
				return invoke;
			}
		});

		HelloService helloService1 = (HelloService) enhancer.create();
		helloService1.sayHello();
	}

}
